package com.wc.alorithm_blue_bridge._BFS.青蛙跳杯子;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @Author congge
 * @Date 2024/9/13 15:36
 * @description https://www.lanqiao.cn/problems/102/learning/?page=1&first_category_id=1&second_category_id=3
 */
public class Main {
    /**
     * 思路：典型的BFS
     * 将字符串转换为数字进行交换，比较容易
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1000010;
    static String s, ed;
    static long a = 0, b = 0;
    static int n;
    static Queue<long[]> q = new LinkedList<>();
    static long[] bit = new long[16];

    public static void main(String[] args) {
        s = sc.next();
        ed = sc.next();
        bit[0] = 1;
        for (int i = 1; i < 16; bit[i] = bit[i - 1] * 10, i++) ;
        n = s.length();
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'W') a = a * 10 + 1;
            if (s.charAt(i) == 'B') a = a * 10 + 2;
            if (s.charAt(i) == '*') a = a * 10 + 3;
        }
        for (int i = 0; i < n; i++) {
            if (ed.charAt(i) == 'W') b = b * 10 + 1;
            if (ed.charAt(i) == 'B') b = b * 10 + 2;
            if (ed.charAt(i) == '*') b = b * 10 + 3;
        }
        q.add(new long[]{a, 0});
        // 不要有重复的数
        Set<Long> set = new HashSet<>();
        set.add(a);
        while (!q.isEmpty()) {
            long[] t = q.poll();
            long x = t[0], stp = t[1];
            if (x == b) {
                out.println(stp);
                out.flush();
                return;
            }
            // 找到空杯子的位置
            int blank = 0;
            for (int i = 0; i < n; i++) {
                if (x / bit[i] % 10 == 3) {
                    blank = i;
                    break;
                }
            }
            // 可以交换的位置
            for (int i = Math.max(0, blank - 3); i <= Math.min(n - 1, blank + 3); i++) {
                long num = x / bit[i] % 10;
                long y = x - num * bit[i] + num * bit[blank] - 3 * bit[blank] + 3 * bit[i];
                if (!set.contains(y)) {
                    set.add(y);
                    q.add(new long[]{y, stp + 1});
                }
            }
        }

    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}